fix: base64DecodeBytes unsigned byte values + improve JMH benchmark config#705
Closed
He-Pin wants to merge 1 commit intodatabricks:masterfrom
Closed
fix: base64DecodeBytes unsigned byte values + improve JMH benchmark config#705He-Pin wants to merge 1 commit intodatabricks:masterfrom
He-Pin wants to merge 1 commit intodatabricks:masterfrom
Conversation
This was referenced Apr 6, 2026
bb5274e to
d1c2cb4
Compare
- Add regression test base64DecodeBytes_unsigned.jsonnet verifying that bytes >= 128 are returned as unsigned values (0-255). This serves as a guard against regressions after the & 0xff fix was merged in master. - Increase JMH RegressionBenchmark warmup/measurement iterations from 1 to 3, providing more stable and reliable benchmark results. 🤖 Generated with [Qoder][https://qoder.com]
d1c2cb4 to
56dc21d
Compare
Contributor
Author
|
Closing this PR since the Note: The regression test |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
std.base64DecodeByteswas returning signed Java byte values (-128..127) instead of the Jsonnet-standard unsigned range (0..255). Bytes with the high bit set (≥128) were returned as negative numbers, violating the specification.Key Design Decision
Apply
& 0xffmask to convert signed Java bytes to unsigned integers, matching the Jsonnet specification and behavior of the C++, Go, and Rust implementations.Modification
sjsonnet/src/sjsonnet/stdlib/EncodingModule.scala(base64DecodeBytes):& 0xffmask:decoded(i) & 0xffconverts signed byte (-128..127) to unsigned int (0..255)Test:
new_test_suite/base64DecodeBytes_unsigned.jsonnet— verifies bytes ≥ 128 are returned as unsigned (e.g., 0xff → 255, not -1)Benchmark Results
This is a correctness fix, not a performance optimization. No benchmark impact expected.
Analysis
bytetype is signed (-128..127).Base64.getDecoder.decode()returnsbyte[]. Without masking, values ≥ 128 are negative.[0, 255]range.References
bytetype: signed, -128 to 127& 0xffmask: standard Java idiom for unsigned byte conversionResult
Fixes
std.base64DecodeBytesto return unsigned byte values (0-255) per the Jsonnet specification.